package com.hut.oa.model.dao.file;

import java.util.List;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;

import com.hut.oa.model.bean.Directory;
import com.hut.oa.model.bean.User;

public interface DirectoryDao extends CrudRepository<Directory,Long>{
	
	List<Directory> findByPidAndUserAndIsDelete(Directory pid,User u,Integer isdelete);
	
	
	@Query("update Directory d set d.text=:name where id=:id")
	@Modifying
	int updatenewname(@Param("id")Long id,@Param("name")String name);
	
	@Query("select d from Directory d")
	List<Directory> selectAlldirect();
	
	List<Directory> findByDirpermissionAndIsDelete(String permission,Integer isdelete);
	
	@Query("select dir from Directory dir where permission=:permission  and text like CONCAT('%',:text,'%')")
	List<Directory> findlikeText(@Param("permission")String permission,@Param("text")String text);
	
	List<Directory> findByPidIsNullAndUserAndIsDelete(User u,Integer isdelete);
	
	
	Directory findById(Long id);
	
	Directory findByIdAndText(Long id,String value);
	
	List<Directory> findByPid(Directory dir);
	
	List<Directory> findByPidAndIsDelete(Directory dir,Integer isdel);
	@Query("update Directory d set isDelete=1 where id=:id")
	@Modifying
	int updateid(@Param("id")Long id);
	
	Directory findByUserAndPidIsNull(User user);
	
	@Query("select dir from Directory dir where user=:user and text like CONCAT('%',:text,'%')")	
	List<Directory> findlikeTextanduser(@Param("text")String text,@Param("user")User u);
	
	List<Directory> findByIsDeleteAndUserAndPid(Integer isdelete,User user,Directory dir);
}
